package com.hongkuncheng.cms.model;

import javax.persistence.*;
import java.util.List;
import java.util.Objects;
import java.io.Serializable;

@Entity
public class Department implements Serializable {
    protected int id;
    protected String name;
    protected String urldirectory;
    protected String template;
    protected int sort;
    protected List<Admin> admins;
    protected List<ColumnsReDepartment> columnsReDepartments;
    protected List<DataitemReDepartment> dataitemReDepartments;
    protected Datamodel datamodel;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Basic
    @Column(name = "name", nullable = false, length = 255)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Basic
    @Column(name = "urldirectory", nullable = true, length = 255)
    public String getUrldirectory() {
        return urldirectory;
    }

    public void setUrldirectory(String urldirectory) {
        this.urldirectory = urldirectory == null || urldirectory.isEmpty() ? null : urldirectory;
    }

    @Basic
    @Column(name = "template", nullable = true, length = 255)
    public String getTemplate() {
        return template;
    }

    public void setTemplate(String template) {
        this.template = template == null || template.isEmpty() ? null : template;
    }

    @Basic
    @Column(name = "sort", nullable = false)
    public int getSort() {
        return sort;
    }

    public void setSort(int sort) {
        this.sort = sort;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Department that = (Department) o;
        return id == that.id &&
                sort == that.sort &&
                Objects.equals(name, that.name) &&
                Objects.equals(urldirectory, that.urldirectory) &&
                Objects.equals(template, that.template);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, urldirectory, template, sort);
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "department")
    public List<Admin> getAdmins() {
        return admins;
    }

    public void setAdmins(List<Admin> admins) {
        this.admins = admins;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "department")
    public List<ColumnsReDepartment> getColumnsReDepartments() {
        return columnsReDepartments;
    }

    public void setColumnsReDepartments(List<ColumnsReDepartment> columnsReDepartments) {
        this.columnsReDepartments = columnsReDepartments;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "department")
    public List<DataitemReDepartment> getDataitemReDepartments() {
        return dataitemReDepartments;
    }

    public void setDataitemReDepartments(List<DataitemReDepartment> dataitemReDepartments) {
        this.dataitemReDepartments = dataitemReDepartments;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "datamodel_id", referencedColumnName = "id")
    public Datamodel getDatamodel() {
        return datamodel;
    }

    public void setDatamodel(Datamodel datamodel) {
        this.datamodel = datamodel;
    }
}
